using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ProtectThePieWP7.AdditionalClasses
{
    public class GameStringSystem
    {
        private int maxStringCount;
        private List<GameString> stringList;

        public GameStringSystem(int maxStringCount)
        {
            this.maxStringCount = maxStringCount;
            stringList = new List<GameString>();
        }

        public void Update()
        {
            int i = 0;
            while (i < stringList.Count)
            {
                if (!stringList[i].Update())
                {
                    RemoveString(stringList[i]);
                }
                else i++;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < stringList.Count; i++)
            {
                stringList[i].Draw(spriteBatch);
            }
        }

        public void AddString(GameString gameString)
        {
            stringList.Add(gameString);

            stringList[stringList.Count - 1].Update();

            if (stringList.Count > maxStringCount)
                RemoveString(stringList[0]);
        }

        private void RemoveString(GameString gameString)
        {
            stringList.Remove(gameString);
        }

        public int Count()
        {
            return stringList.Count;
        }

        public void Clear()
        {
            stringList.Clear();
        }
    }
}
